package com.example.design.status;

import com.example.design.status.observer.ActivityObserver;
import com.example.design.status.observer.Subject;
import com.example.design.status.observer.TaskMangeObserver;

/**
 * @author: Bin.L
 * @date: 2022/3/14 11:30
 * @Description: 任务进行状态
 */

public class TaskOngoing extends Subject implements State {

    public TaskOngoing() {
        add(new ActivityObserver());
        add(new TaskMangeObserver());
    }

    @Override
    public void update(TaskTest task, DefinitionEnum.ActionType actionType) {
        if (actionType == DefinitionEnum.ActionType.ACHIEVE) {
            // task.setState(new TaskFinished());
            System.out.println("任务完成,更改状态为完成");
            // 观察者模式调用通知
            notifyObserver(" 观察者模式调用通知 ");
            System.out.println("完成任务后的业务处理");
            // taskManager.release(taskId);
        } else if (actionType == DefinitionEnum.ActionType.STOP) {
            task.setState(new TaskPaused());
        } else if (actionType == DefinitionEnum.ActionType.EXPIRE) {
            // task.setState(new TaskExpired());
            System.out.println("行为过期, 任务变过期状态");
        }
    }
}
